home *** CD-ROM | disk | FTP | other *** search
- /* $VER: AltSpam.thor V0.4 (29/6/97)
- * Takes an unsuccessful complaint & parses out the real & IP addresses to
- * add to a file. This file can be used by TASC.thor to tell you when it's pointless
- * to complain & to offer you an alternative address.
- * Also gives you the option to resend your original complaint.
- */
-
-
- /*============Don't change anything below here==================*/
-
- options results
- options failat 31
-
- /* Read the config file & set up defalts if it isn't there */
- if open(cfg,'Env:thor/TASC.cfg',r) then do
- do until eof(cfg)
- lin=readln(cfg)
- parse var lin id ':' V
- V=strip(V)
- if upper(left(id,6))='BOUNCE' then
- Bounce=V
- if upper(left(id,4))='MINE' then
- Mine=V
- if upper(left(id,10))='POSTMASTER' then
- Postmaster=V
- if upper(left(id,8))='DATABASE' then
- spamdb=V
- end
- call close(cfg)
- end
- else do
- Bounce=''
- Mine=''
- Postmaster=''
- spamdb='rexx/spam.db'
- end
-
- FRM=''
- failed.=''
- spamfail.=''
- email.=''
- i=1
-
- thorport = address()
- if left(thorport, 5) ~= 'THOR.' then do
- say 'Cannot find thorport.'
- exit
- end
-
- if ~show('p', 'BBSREAD') then do
- address command
- "run >nil: `GetEnv THOR/THORPath`bin/LoadBBSRead"
- "WaitForPort BBSREAD"
- end
-
- if open(A,'env:thor/thorpath') then do
- THORP=READLN(A)
- call close(A)
- end
-
- address(thorport)
-
- CURRENTMSG stem MSG
- if (rc ~= 0) then call oops("No current message.")
-
- SAVEMESSAGE CURRENT FILE "T:AltSpam.temp"
- if(rc ~= 0) then call oops("Unable to save current message.")
-
- IF Open(A,'T:Altspam.temp','r') = 0 THEN DO
- call oops("Couldn't open temporary file")
- EXIT 20
- END
-
- do until index(hder,'X-Mailer: THOR')~=0
- /* A header line belonging to Thor. We assume that no one runs their
- mailserver with Thor */
- hder= readln(A)
- if upper(left(hder,5))='FROM:' then do
- Call FRM
- end
- if upper(left(hder,3))='TO:' then do
- Call TOHDR
- end
- if upper(left(hder,9))='ORIGINAL-' then do
- Call ORIG
- end
- if upper(left(hder,6))='FINAL-' then do
- Call FIN
- end
- end
- close(A)
-
- /* Now ask what we should do the next time that we meet these addresses */
- if open(A,THORP||spamdb,'r') then do
- DO WHILE ~Eof(A)
- f=readln(A)
- parse VAR f wrong '->' correct
- do j=1 to i
- parse VAR spamfail.j gubbins ':' addr
- if wrong=addr then do
- spamfail.j=''
- end
- end
- END
- end
- a=1
- do j=1 to i
- if spamfail.j~='' then do
- failed.a=spamfail.j
- a=a+1
- end
- end
- failed.count=a-1
- if failed.count<1 then call oops("All addresses are assigned already.\n Try editing the "||THORP||spamdb||" file by hand.")
- drop spamfail.
-
- address(Thorport)
-
- Requestlist Instem failed outstem spamfail dragselect multiselect title '"Add which addresses?"'
- IF (RC > 0) THEN call oops("No Addresses Selected")
-
- do i=1 to failed.count
- parse VAR failed.i gubbins ':' failed.i
- end
-
- do i=1 to spamfail.count
- parse VAR spamfail.i gubbins ':' spamfail.i
- end
-
- k=2
- do i=1 to spamfail.count
- drop email.
- email.1='Mark as Undeliverable'
- if FRM~='' then do
- email.k=FRM
- k=k+1
- end
- Call ParseAlt
- Call PickAlt
- call Remail
- end
-
- call cleanup
-
- FRM:
- if index(hder,mine)=0 then do
- parse VAR hder gubbins '<' pm '@' FRM '>'
- end
- return
-
- TOHDR:
- parse VAR hder gubbins '<' pm '@' TOHDR '>'
- if TOHDR=Bounce then return
- if index(TOHDR,',')~=0 then do until index(TOHDR,',')=0
- parse VAR TOHDR tohd ',' pm '@' TOHDR
- spamfail.i='[TO Postmaster@ ]:'||tohd
- i=i+1
- end
- spamfail.i='[TO Postmaster@ ]:'||TOHDR
- spamfail.count=i
- i=i+1
- return
-
- ORIG:
- parse VAR hder gubbins ';' pm '@' ORIG
- spamfail.i='[Original-Recipient]:'||ORIG
- spamfail.count=i
- i=i+1
- return
-
- FIN:
- parse VAR hder gubbins ';' pm '@' FIN
- spamfail.i='[Final-Recipient ]:'||FIN
- spamfail.count=i
- i=i+1
- return
-
- ParseAlt:
- if left(spamfail.i,1)='[' then do
- do j=1 to failed.count
- if left(failed.j,1)~='[' then do
- baseaddr=failed.j
- Call parseaddr
- parsed='Y'
- end
- end
- if parsed~='Y' then do
- email.k='No alternative addresses'
- k=k+1
- end
- end
- else do
- baseaddr=spamfail.i
- Call Parseaddr
- end
- return
-
- Parseaddr:
- email.k=baseaddr
- k=k+1
- do until index(baseaddr,'.')=0
- parse VAR baseaddr lwr '.' hghr
- if index(hghr,'.')~=0 then do
- email.k=hghr
- k=k+1
- end
- baseaddr=hghr
- end
- return
-
- PickAlt:
- email.count=k-1
- newaddr.=''
- Requestlist Instem email outstem newaddr title '"Substitute which address for '||spamfail.i||'?"'
- IF (RC > 0) THEN DO
- REQUESTNOTIFY TEXT '"No Addresses Selected"' BT '"_Ok"'
- return
- END
- newaddr=result
- if newaddr='No alternative addresses' then
- newaddr='Undeliverable'
- if newaddr='Mark as Undeliverable' then
- newaddr='Undeliverable'
- address command
- 'echo '||spamfail.i||'->'||newaddr||' >> '||THORP||spamdb
- return
-
- Remail:
- address(thorport)
- if newaddr='Undeliverable' then return
- if newaddr~=spamfail.i then do
- adder='Remail complaint to '||newaddr||' (was '||spamfail.i||')?'
- requestnotify text '"' adder '"' BT '"_Yes|_No"'
- if result=0 then return
- if open(A,'T:altspam.temp','r')>0 then do
- hder=readln(A)
- do until index(hder,'X-Mailer: THOR')~=0
- hder=readln(A)
- end
- CURRENTMSG stem MSG
- address bbsread
- UNIQUEMSGFILE bbsname '"'MSG.BBSNAME'"' stem tmp
- if (rc ~= 0) then call oops
- if open(B,tmp.NAME,'w')>0 then do
- if Postmaster~='' then do
- call Writeln (B,'"From: postmaster@'||Postmaster||'"')
- call Writeln (B,"")
- end
- do until eof(A)
- hder=readln(A)
- writeln(B,hder)
- end
- call close(B)
- end
- call close(A)
- end
- EVE_ENTERMSG = 0
- drop EVENT.
- EVENT.TONAME = 'Postmaster'
- EVENT.TOADDR = 'Postmaster@'||newaddr
- EVENT.SUBJECT = 'Spam/Email abuse'
- EVENT.CONFERENCE = 'EMail'
- EVENT.MSGFILE = tmp.FILEPART
- EVENT.URGENT = 0
- WRITEBREVENT bbsname '"'MSG.BBSNAME'"' event EVE_ENTERMSG stem EVENT
- end
- return
-
- oops:
- PARSE ARG errmsg
- if errmsg = '' then do
- if address() = "BBSREAD" then errmsg=BBSREAD.LASTERROR
- else errmsg=THOR.LASTERROR
- end
- address(thorport)
- REQUESTNOTIFY TEXT '"' errmsg '"' BT '"_Abort"'
- call cleanup
- return
-
-
- cleanup:
- address command 'delete >nil: T:AltSpam.temp'
- exit
-